//
//  ToolsModel.m
//  UI17-网络封装
//
//  Created by 张诗雨 on 14/12/18.
//  Copyright (c) 2014年 张诗雨. All rights reserved.
//

#import "ToolsModel.h"

@implementation ToolsModel
+ (NSString *)libraryPathWithName:(NSString *)filedName
{
    NSArray *array =NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
    NSString *path = [array firstObject];
    path = [NSString stringWithFormat:@"%@/%@",path, filedName];
    return path;
}
+ (void)saveFileData:(NSData *)data filedNamed:(NSString *)filedNamed
{
    NSString *path = [ToolsModel libraryPathWithName:filedNamed];
    [data writeToFile:path atomically:YES];
    
}

+ (NSData *)readFileNamed:(NSString *)filedNamed
{
    NSString *path = [ToolsModel libraryPathWithName:filedNamed];
    BOOL file = [ToolsModel fileExsts:filedNamed];
    if (file) {
        NSData *data = [NSData dataWithContentsOfFile:path];
        return data;
    }
    return [NSData data];
}
+(BOOL)fileExsts:(NSString *)fileName
{
    NSString *path = [ToolsModel libraryPathWithName:fileName];
    NSFileManager *manager = [NSFileManager defaultManager];
    return [manager fileExistsAtPath:path];
}
@end
